package com.golf.core.course.loader;

import java.util.ArrayList;
import java.util.List;

import com.golf.core.course.Course;
import com.golf.core.course.exceptions.CourseLoadException;

/**
 * A class that can choose a new course. 
 * 
 * @author gareth
 */
public class CoursePicker
{

    /** The singleton instance of this class. */
    private static final CoursePicker INSTANCE = new CoursePicker();
    
    /** The available courses to choose from. */
    private final List<String> COURSES = new ArrayList<String>();
    // ^^^^ not theread safe
    
    
    /**
     * The private constructor.
     */
    private CoursePicker()
    {
        // Add the courses that are available - // TODO: this should be intelligent .... (auto search, etc.)
        COURSES.add("course.xml");
    }
    
    
    /**
     * Get the singleton picker instance.
     * 
     * @return The course picker instance.
     */
    public static CoursePicker getInstance()
    {
        return INSTANCE;
    }
    
    
    /**
     * Choose a random course.
     * 
     * @return The randomly chose course.
     * @throws CourseLoadException If there is a problem loading a chosen course.
     */
    public Course randomCourse() 
    throws CourseLoadException
    {
        String courseName = null;
        synchronized (COURSES)
        {
            courseName = COURSES.get(0);   // NB: NOT RANDOM YET !!!!!!!!
        }
        
        return CourseLoader.load(courseName);
    }
    
}
